<template>
  <accuracyPlanDetail v-if="detailVisible" @changeDetailVisible="changeDetailVisible" :effPlanDetail="effDetail"></accuracyPlanDetail>
  <addAccuracyPlan v-else-if="addVisible" @addMaintain="addMaintain" :mainDevice="deviceList" :factoryList="companyList" :planPositionList="positionList" :planClassifyList="classifyList" @handlePlanOk="handlePlanOk" :editId="id"></addAccuracyPlan>
  <div class="project zy-content" v-else>
    <div class="title">
      <span>精度检测计划</span>
      <div class="icon">
        <span class="creatBtnright" @click="addMaintain(true)" v-if="checkBtnPermission.dcmAcctestPlanAdd">
          <span><Icon type="ios-add-circle-outline" color="#187BDB" /></span>
          <span class="rightbtn">新增检测计划</span>
        </span>
      </div>
    </div>
    <Tabs @on-click="tabsClick" v-model="status" :animated="false">
      <TabPane label="有效计划">
      </TabPane>
      <TabPane label="无效计划">
      </TabPane>
    </Tabs>
    <effectivePlan v-if="status == 0" :planIds="ids" @addMaintain="addMaintain" @changeDetailVisible="changeDetailVisible" :device="deviceList" :effPlanList="effList" :effPlanTotal="effTotal" :permission="checkBtnPermission"/>
    <invalidPlan v-else :planIds="ids" @addMaintain="addMaintain" @changeDetailVisible="changeDetailVisible" :device="deviceList" :invalidPlanList="invalidList" :invalidPlanTotal="invalidTotal" :permission="checkBtnPermission"></invalidPlan>
  </div>
</template>

<script>
import checkDetail from './modal/checkDetail.vue'
import addAccuracyPlan from './modal/addAccuracyPlan'
import effectivePlan from './modal/effectivePlan.vue'
import invalidPlan from './modal/invalidPlan.vue'
import accuracyPlanDetail from './modal/accuracyPlanDetail'

export default {
  name: "accuracyPlan",
  components: {
    checkDetail,
    accuracyPlanDetail,
    addAccuracyPlan,
    effectivePlan,
    invalidPlan
  },
  data() {
    return {
      id: '',
      ids: [],
      status: 0,
      effTotal: 0,
      invalidTotal: 0,
      addVisible: false,
      detailVisible: false,
      effDetail: {},
      checkBtnPermission: {},
      deviceList: [],
      companyList: [],
      positionList: [],
      classifyList: [],
      effList: [],
      invalidList: [],

    }
  },
  created() {
    this.getDeviceList()
    this.getCompanyList()
    this.getPositionList()
    this.getClassifyList()
    this.searchList()
  },
  mounted() {
    let itemList = JSON.parse(window.localStorage.getItem('USER_URI'))
    for(let item of itemList){
      if(item.code=="dcmAcctestPlanAdd"){
        this.checkBtnPermission.dcmAcctestPlanAdd = true
      }
      if(item.code=="dcmAcctestPlanEdit"){
        this.checkBtnPermission.dcmAcctestPlanEdit = true
      }
      if(item.code=="dcmAcctestPlanQueryById"){
        this.checkBtnPermission.dcmAcctestPlanQueryById = true
      }
      if(item.code=="dcmAcctestPlanDelete"){
        this.checkBtnPermission.dcmAcctestPlanDelete = true
      }
      if(item.code=="dcmAcctestPlanList"){
        this.checkBtnPermission.dcmAcctestPlanList = true
      }
      if(item.code=="dcmAcctestPlanDeleteBatch"){
        this.checkBtnPermission.dcmAcctestPlanDeleteBatch = true
      }
      if(item.code=="dcmAcctestDisableRecordDisable"){
        this.checkBtnPermission.dcmAcctestDisableRecordDisable = true
      }
      if(item.code=="dcmAcctestDisableRecordBatchDisable"){
        this.checkBtnPermission.dcmAcctestDisableRecordBatchDisable = true
      }
      if(item.code=="dcmAcctestDisableRecordEnable"){
        this.checkBtnPermission.dcmAcctestDisableRecordEnable = true
      }
      if(item.code=="dcmAcctestDisableRecordBatchEnable"){
        this.checkBtnPermission.dcmAcctestDisableRecordBatchEnable = true
      }
      if(item.code=="dcmAcctestDisableRecordList"){
        this.checkBtnPermission.dcmAcctestDisableRecordList = true
      }

    }
  },
  methods: {
    /**************基础数据**********************/
    getDeviceList() {
      this.axios({
        method: 'get',
        url: '/dms/dmsCategory/getSelectList',
        params: {}
      }).then(res => {
        if(res.code === 200){
          this.deviceList = res.data.map(item => {
            return {
              ...item,
              value: item.value.toString()
            }
          })
        }else{
          this.$Message.warning(({content:res.msg,duration:6,closable:true}));
        }
      })
    },
    //公司列表
    getCompanyList() {
      this.axios({
        method: 'get',
        url: '/basic/company/getCompanyListByUser',
        params: {}
      }).then(res => {
        if(res.code === 200){
          this.companyList = res.data
        }else{
          this.$Message.warning(({content:res.msg,duration:6,closable:true}));
        }
      })
    },
    getPositionList() {
      this.axios({
        method: 'get',
        url: '/dms/dcmAcctestPosition/getSelectList',
        params: {}
      }).then(res => {
        if(res.code === 200){
          this.positionList = res.data
        }else{
          this.$Message.warning(({content:res.msg,duration:6,closable:true}));
        }
      })
    },
    getClassifyList() {
      this.axios({
        method: 'get',
        url: '/dms/dcmAcctestClassify/getSelectList',
        params: {}
      }).then(res => {
        if(res.code === 200){
          this.classifyList = res.data
        }else{
          this.$Message.warning(({content:res.msg,duration:6,closable:true}));
        }
      })
    },
    tabsClick(name) {
      console.log(name)
      this.status = name
      this.ids = []
      this.searchList()
      // if (name === 0) {
      //     this.$refs.productConfigComponent.searchBtn();
      // } else  if (name === 1){
      //     console.log(this.$$refs);
      //     this.$refs.boxConfigComponent.searchBtn();
      // }else{
      //     this.$refs.shfitconfigComponent.searchBtn();
      // }
    },
    searchList() {
      let params = {
        status: this.status,
        pageNo:1,
        pageSize:10,
      };
      // for (let key in this.searchParams) {
      //   if (key === 'orgId' && this.searchParams['orgId']) {
      //     const arr = this.searchParams[key]
      //     const { length, last=length-1 } = arr
      //     this.$set(params, key, arr[last])
      //   }else {
      //     if (this.searchParams[key]) {
      //       this.$set(params, key, this.searchParams[key])
      //     }
      //   }
      //
      // }
      this.axios({
        method: 'get',
        url: '/dms/dcmAcctestPlan/list',
        params
      }).then(res => {
        
        if(res.code === 200){
          if (this.status == 0) {
            this.effList = res.data.list
            this.effTotal = res.data.total
          }else {
            this.invalidList = res.data.list
            this.invalidTotal = res.data.total
          }
        }else{
          this.$Message.warning(({content:res.msg,duration:6,closable:true}));
        }
      })
    },
    handlePlanOk() {
      console.log('新增成功')
      this.addVisible = false
      // this.status = 0
      this.searchList()
    },
    addMaintain(flag, record) {
      console.log(flag, record)
      let obj = record ? record : {}
      this.addVisible = flag
      if (obj.id) {
        this.id = record.id
      }else {
        this.id = ''
      }
    },
    changeDetailVisible(flag, id) {
      console.log('11')
      this.detailVisible = flag
      this.getEffDetail(id)
      // this.status = 0
      this.searchList()
    },
    getEffDetail(id) {
      this.axios({
        method: 'get',
        url: '/dms/dcmAcctestPlan/queryById',
        params: {
          id
        }
      }).then(res => {
        if(res.code === 200){
          this.effDetail = res.data
        }else{
          this.$Message.warning(({content:res.msg,duration:6,closable:true}));
        }
      })
    },
  },
};
</script>

<style lang="scss">
  .project{
    //background: #fff;
    .title {
      display: flex;
      justify-content: space-between;
      font-size: 20px;
      padding: 10px;
      border-bottom: 1px solid #dddddd;
      .icon {
        display: flex;
        .creatBtnright {
          display: flex;
          align-items: center;
          font-size: 16px;
          i {
            font-size: 36px;
          }
        }
      }
    }
    /*.tab {*/
    /*  height: calc(100% - 100px);*/
    /*  .ivu-tabs-bar {*/
    /*    padding-left: 30px;*/
    /*    .ivu-tabs-tabpane {*/
    /*      height: calc(100% - 100px);*/
    /*      overflow-y: scroll;*/
    /*    }*/
    /*  }*/
    /*  .ivu-tabs-tab {*/
    /*    font-size: 18px;*/
    /*  }*/
    /*}*/
    .ivu-tabs-tab {
      font-size: 18px;
    }
  }
</style>
